package com.lsk.mps.backend.controller;

import com.lsk.mps.backend.aspect.annotation.JsonReturn;
import com.lsk.mps.backend.redis.RedisDao;
import com.lsk.mps.backend.service.MessageService;
import com.lsk.mps.backend.service.UserService;
import com.lsk.mps.backend.util.SseEmittersHolder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;

import java.util.UUID;

@Slf4j
@RestController
@RequestMapping("/api/user/")
public class UserController {
    @Autowired
    private UserService userService;
    @Autowired
    private MessageService messageService;

    @JsonReturn
    @GetMapping("/changeUsername")
    public Object changeUsername(String newUsername) {
        userService.changeUsername(newUsername);
        return "Success";
    }

    @JsonReturn
    @GetMapping("/changePassword")
    public Object changePassword(String newPassword) {
        userService.changePassword(newPassword);
        return "Success";
    }

    @JsonReturn
    @GetMapping("/message/pages")
    public Object messagePages() {
        return messageService.messagePages();
    }

    @JsonReturn
    @GetMapping("/message/list")
    public Object queryMessages(Integer page) {
        return messageService.allMessages(page);
    }

    @JsonReturn
    @PostMapping("/message/confirm")
    public Object messageConfirm(Integer targetID, String content) {
        messageService.confirmMessage(targetID, content);
        return "Success";
    }
}
